package com.cj.sys.service.security;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.intercept.web.FilterInvocationDefinitionSource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cj.common.orm.hibernate.EntityManager;
import com.cj.common.security.springsecurity.FilterSecurityInterceptor;
import com.cj.sys.dao.security.AuthorityDao;
import com.cj.sys.entity.security.Authority;

/**
 * 授权管理类.
 * 
 * @author calvin
 */
@Service
@Transactional
public class AuthorityManager extends EntityManager<Authority, Long> {
	@Autowired
	AuthorityDao authorityDao;
	
	@Autowired
	private FilterSecurityInterceptor filterSecurityInterceptor;
	
	@Autowired
	@Qualifier("databaseDefinitionSource")	
	private FactoryBean databaseDefinitionSource;
	
	@Override
	protected void afterChange(Authority entity) {
		try {
			filterSecurityInterceptor.setObjectDefinitionSource((FilterInvocationDefinitionSource)databaseDefinitionSource.getObject());
		} catch (Exception e) {
			logger.error("更新权限错误!",e);
		}
	}
	
	@Override
	protected AuthorityDao getEntityDao() {
		return authorityDao;
	}

}
